package com.wms.controller;

import com.wms.bean.PageBean;
import com.wms.bean.ResultBean;
import com.wms.core.R;
import com.wms.entity.Purchase;
import com.wms.service.PurchaseService;
import com.wms.utils.Assert;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "到货登记")

public class PurchaseController {

    @Autowired
    PurchaseService purchaseService;

    @GetMapping("/arrival/info")
    @ApiOperation("获取列表信息")
    public ResultBean getAll(){
        List list= purchaseService.getAll();
        return R.success("返回所有列表信息",list);
    }

    @PostMapping("/arrival/bycondition")
    @ApiOperation("多条件查询")
    public ResultBean<List<Purchase>> queryByCondition(@RequestBody Purchase condition){
        List<Purchase> list= purchaseService.queryByCondition(condition);
        return R.success("查询成功",list);
    }

    @GetMapping("/arrival/page")
    @ApiOperation("分页查询")
    public ResultBean<PageBean<Purchase>> queryByPage(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "5") int pageSize){
        PageBean pageBean= purchaseService.queryByPage(page,pageSize);
        return R.success("分页信息",pageBean);
    }

    @GetMapping("/arrival/purchaseDetiil")
    @ApiOperation("采购明细")
    public ResultBean queryPurchaseDetail(@RequestParam int id){
        List list= purchaseService.queryPurchaseDetail(id);
        return R.success("查询成功",list);
    }
    @PostMapping("/arrival/saveAll")
    @ApiOperation("保存采购单")
    public ResultBean saveAll(@RequestBody Purchase purchase){
        Assert.isEmpty(purchase.getPurchaseMaterials(),"采购单明细不能为空");
        int n=purchaseService.savePurchase(purchase);
        return n==1?R.success("保存成功"):R.fail("保存失败");
    }

    @GetMapping("/arrival/purchaseGoods")
    @ApiOperation("采购商品明细")
    public ResultBean queryPurchaseGoods(@RequestParam String purchaseCode){
        List list=purchaseService.queryPurchaseGoods(purchaseCode);
        return R.success("查询成功",list);
    }

}
